package flca.voicenav.util;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import flca.voicenav.R;
import flca.voicenav.model.VoiceNavData;

public class ButtonMgr
{
	private Activity mActivity;
	private boolean loadBtnEnabled = true;
	private boolean startedClicked = false;
	private boolean locationNearRoute = false;

	private Button startBtn;
	private Button loadBtn;

	public ButtonMgr(Activity aActv)
	{
		super();
		this.mActivity = aActv;

		this.startBtn = (Button) mActivity.findViewById(R.id.start);
		this.loadBtn = (Button) mActivity.findViewById(R.id.load);
		initButtonState();
	}

	private void initButtonState()
	{
		startBtn.setEnabled(startEnabled());
		loadBtn.setEnabled(loadBtnEnabled);
	}

	public void onStartClicked()
	{
		startedClicked = true;
		loadBtnEnabled = false;
		initButtonState();
	}

	private boolean startEnabled() {
		return locationNearRoute && VoiceNavData.getGpxRoute() != null && !startedClicked;
	}
	public void onLoadClicked() {
		initButtonState();
	}

	public void routeFound() {
		this.locationNearRoute = true;
		initButtonState() ;
	}
	
	//---- 
	public void saveState(Bundle savedInstanceState) 
	{
		savedInstanceState.putBoolean("buttonmgr_b1", loadBtnEnabled);
		savedInstanceState.putBoolean("buttonmgr_b2", startedClicked);
		savedInstanceState.putBoolean("buttonmgr_b3", locationNearRoute);
	}

	public void restoreState(Bundle savedInstanceState) 
	{
		loadBtnEnabled = savedInstanceState.getBoolean("buttonmgr_b1");
		startedClicked = savedInstanceState.getBoolean("buttonmgr_b2");
		locationNearRoute = savedInstanceState.getBoolean("buttonmgr_b3");
	}
	
	
}
